package com.csc.banking.controller;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.csc.banking.bo.RoleBO;
import com.csc.banking.domain.Role;



/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	@Autowired
	private RoleBO roleBO;
	
	
	private static final Logger logger = LoggerFactory
			.getLogger(HomeController.class);

	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Locale locale, Model model) {
		logger.info("Welcome home! The client locale is {}.", locale);

		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,
				DateFormat.LONG, locale);

		String formattedDate = dateFormat.format(date);

		model.addAttribute("serverTime", formattedDate);
		
		/*printRoles(roleBO.getAllRoles());
		
		
		Role role = new Role();
		role.setIdRole(1);
		role.setRoleName("admin");
		role.setDescription("This is admin");
		System.out.println("addRole()...");
		roleBO.addRole(role);
		
		Role role2 = new Role();
		role2.setIdRole(2);
		role2.setRoleName("user");
		role2.setDescription("This is user");
		System.out.println("addRole()...");
		roleBO.addRole(role2);
		
		printRoles(roleBO.getAllRoles());
		
		Role role3 = new Role();
		role3.setIdRole(1);
		role3.setRoleName("admin++");
		role3.setDescription("This is admin++");
		System.out.println("updateRole()..");
		roleBO.updateRole(role3);
		
		printRoles(roleBO.getAllRoles());
		
		System.out.println("deleteRole()...");
		roleBO.deleteRole(2);
		
		printRoles(roleBO.getAllRoles());*/
		
		
		return "home";
	}
	
	private void printRoles(List<Role> roles){
		for (Role r : roles) {
			System.out.println("-----------");
			System.out.println("IdRole = "+r.getIdRole());
			System.out.println("RoleName = "+r.getRoleName());
			System.out.println("Description = "+r.getDescription());
		}
	}

}
